var fw = require("./frameworkFunctions_server");
var logger = require("./logger").logger;

exports.onSessionCreate = function () {
	//Build here the initial DOM
	fw.document = fw.parser.parseFromString("<root>ciao<notizie refname='serverNews'><display><b>Copia testuale:</b></display></notizie><ultimenotizie refname='display'></ultimenotizie></root>");

};

exports.onSessionLoad = function () {
	//Register here event listeners
	fw.registerEventListener(fw.document, ".//notizie/display", "DOMNodeInserted", function(event) {
			var ultime = fw.selectElements(fw.document, ".//ultimenotizie")[0];
			var currentDate = new Date();
			
			//fw.appendChild(event.target, ".", "<b> - "+currentDate.getHours()+":"+currentDate.getMinutes()+":"+currentDate.getSeconds()+"</b>");
			//fw.appendChild(event.relatedNode, ".", "<b> - "+currentDate.toLocaleTimeString() +"</b>");
			var elem = event.target.cloneNode(true);
			ultime.appendChild(elem);
			//fw.removeElements(ultime, "//div[position()<3]");
		});
};